<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 6.3.0">
<link rel="preconnect" href="https://fonts.googleapis.com" crossorigin>
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,300italic,400,400italic,700,700italic%7CZCOOL+QingKe+HuangYou:300,300italic,400,400italic,700,700italic%7CNoto+Sans+Simplified+Chinese:300,300italic,400,400italic,700,700italic%7CJetBrains+Mono:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="/lib/@fortawesome/fontawesome-free/css/all.min.css" integrity="sha256-HtsXJanqjKTc8vVQjO4YMhiqFoXkfBsjBWcX91T1jr8=" crossorigin="anonymous">
  <link rel="stylesheet" href="/lib/animate.css/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="/lib/@fancyapps/ui/dist/fancybox/fancybox.css" integrity="sha256-RvRHGSuWAxZpXKV9lLDt2e+rZ+btzn48Wp4ueS3NZKs=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"wyatex.online","root":"/","images":"/images","scheme":"Pisces","darkmode":true,"version":"8.18.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":false,"height":500},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":true}}</script><script src="/js/config.js"></script>

    <meta name="description" content="一些html5的学习笔记">
<meta property="og:type" content="article">
<meta property="og:title" content="Html5学习笔记（1）">
<meta property="og:url" content="https://wyatex.online/%E5%89%8D%E7%AB%AF/Html5%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-1/index.html">
<meta property="og:site_name" content="Wyatex&#96;s blog">
<meta property="og:description" content="一些html5的学习笔记">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-02-05T11:43:57.000Z">
<meta property="article:modified_time" content="2023-05-05T01:25:47.045Z">
<meta property="article:author" content="Wyatex">
<meta property="article:tag" content="前端">
<meta property="article:tag" content="学习笔记">
<meta property="article:tag" content="HTML">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="https://wyatex.online/%E5%89%8D%E7%AB%AF/Html5%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-1/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://wyatex.online/%E5%89%8D%E7%AB%AF/Html5%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-1/","path":"前端/Html5学习笔记-1/","title":"Html5学习笔记（1）"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>Html5学习笔记（1） | Wyatex`s blog</title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">Wyatex`s blog</p>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">97</span></a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">26</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">155</span></a></li><li class="menu-item menu-item-编程"><a href="/programming/" rel="section"><i class="fa fa-book fa-fw"></i>编程</a></li><li class="menu-item menu-item-蹲坑读物"><a href="/%E5%B9%B2%E8%B4%A7/%E5%BC%80%E5%8F%91%E4%BA%A4%E6%B5%81%E7%BE%A4%E5%88%86%E4%BA%AB%E8%AE%B0%E5%BD%95/" rel="section"><i class="fa fa-book fa-fw"></i>蹲坑读物</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%BB%E8%A6%81%E7%9A%84%E6%A0%87%E7%AD%BE%E5%92%8C%E5%B1%9E%E6%80%A7"><span class="nav-number">1.</span> <span class="nav-text">主要的标签和属性</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%96%B0%E7%9A%84%E5%A4%9A%E5%AA%92%E4%BD%93%E5%85%83%E7%B4%A0"><span class="nav-number">1.1.</span> <span class="nav-text">新的多媒体元素</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%96%B0%E7%9A%84%E8%A1%A8%E5%8D%95%E5%85%83%E7%B4%A0"><span class="nav-number">1.2.</span> <span class="nav-text">新的表单元素</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%96%B0%E7%9A%84%E8%AF%AD%E6%84%8F%E6%A0%87%E7%AD%BE"><span class="nav-number">1.3.</span> <span class="nav-text">新的语意标签</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%9C%A8HTML5%E4%B8%AD%E5%88%A0%E9%99%A4%E7%9A%84HTML4-01%E6%A0%87%E7%AD%BE"><span class="nav-number">1.4.</span> <span class="nav-text">在HTML5中删除的HTML4.01标签</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%A1%A8%E5%8D%95%E7%9A%84%E5%B1%9E%E6%80%A7"><span class="nav-number">1.5.</span> <span class="nav-text">表单的属性</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#form%E6%A0%87%E7%AD%BE%E7%9A%84%E5%B1%9E%E6%80%A7"><span class="nav-number">1.5.1.</span> <span class="nav-text">form标签的属性</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#Web-%E5%82%A8%E5%AD%98"><span class="nav-number">2.</span> <span class="nav-text">Web 储存</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#localStorage-%E5%92%8C-sessionStorage"><span class="nav-number">2.1.</span> <span class="nav-text">localStorage 和 sessionStorage</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#localStorage%E5%AF%B9%E8%B1%A1"><span class="nav-number">2.2.</span> <span class="nav-text">localStorage对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#sessionStorage%E5%AF%B9%E8%B1%A1"><span class="nav-number">2.3.</span> <span class="nav-text">sessionStorage对象</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#HTML5-%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%E7%BC%93%E5%AD%98"><span class="nav-number">3.</span> <span class="nav-text">HTML5 应用程序缓存</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#manifest%E6%96%87%E4%BB%B6"><span class="nav-number">3.1.</span> <span class="nav-text">manifest文件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#CACHE-MANIFEST"><span class="nav-number">3.1.1.</span> <span class="nav-text">CACHE MANIFEST</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#NETWORK"><span class="nav-number">3.1.2.</span> <span class="nav-text">NETWORK</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#FALLBACK"><span class="nav-number">3.1.3.</span> <span class="nav-text">FALLBACK</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#WebSocket"><span class="nav-number">4.</span> <span class="nav-text">WebSocket</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#WebSocket-%E5%B1%9E%E6%80%A7"><span class="nav-number">4.1.</span> <span class="nav-text">WebSocket 属性</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#WebSocket-%E4%BA%8B%E4%BB%B6"><span class="nav-number">4.2.</span> <span class="nav-text">WebSocket 事件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#WebSocket-%E6%96%B9%E6%B3%95"><span class="nav-number">4.3.</span> <span class="nav-text">WebSocket 方法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#WebScoket%E5%AE%9E%E4%BE%8B"><span class="nav-number">4.4.</span> <span class="nav-text">WebScoket实例</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Wyatex"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Wyatex</p>
  <div class="site-description" itemprop="description">这里是我用来做笔记的网站哟~</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">155</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">26</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">97</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/wyatex" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;wyatex" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:wyatex@qq.com" title="E-Mail → mailto:wyatex@qq.com" rel="noopener me" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
    <div class="sidebar-inner sidebar-blogroll">
      <div class="links-of-blogroll animated">
        <div class="links-of-blogroll-title"><i class="fa fa-globe fa-fw"></i>
          链接
        </div>
        <ul class="links-of-blogroll-list">
            <li class="links-of-blogroll-item">
              <a href="https://antfu.me/" title="https:&#x2F;&#x2F;antfu.me&#x2F;" rel="noopener" target="_blank">Anthony Fu</a>
            </li>
            <li class="links-of-blogroll-item">
              <a href="https://www.codesky.me/" title="https:&#x2F;&#x2F;www.codesky.me&#x2F;" rel="noopener" target="_blank">CodeSky</a>
            </li>
            <li class="links-of-blogroll-item">
              <a href="https://learn.lianglianglee.com/" title="https:&#x2F;&#x2F;learn.lianglianglee.com&#x2F;" rel="noopener" target="_blank">技术文章摘抄</a>
            </li>
        </ul>
      </div>
    </div>
        <div class="pjax">
        <div class="sidebar-inner sidebar-post-related">
          <div class="animated">
              <div class="links-of-blogroll-title"><i class="fa fa-signs-post fa-fw"></i>
    相关文章
  </div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      <a class="popular-posts-link" href="/%E5%89%8D%E7%AB%AF/%E8%A7%A3%E5%86%B3mobx-miniprogram%E5%9C%A8TS%E4%B8%8B%E7%9A%84%E4%B8%80%E4%BA%9B%E5%B0%8F%E9%97%AE%E9%A2%98/" rel="bookmark">
        <time class="popular-posts-time">2022-11-03</time>
        <br>
      解决mobx-miniprogram在TS下的一些小问题
      </a>
    </li>
  </ul>

          </div>
        </div>
        </div>
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wyatex.online/%E5%89%8D%E7%AB%AF/Html5%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-1/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Wyatex">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Wyatex`s blog">
      <meta itemprop="description" content="这里是我用来做笔记的网站哟~">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="Html5学习笔记（1） | Wyatex`s blog">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Html5学习笔记（1）
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-02-05 19:43:57" itemprop="dateCreated datePublished" datetime="2020-02-05T19:43:57+08:00">2020-02-05</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-05-05 09:25:47" itemprop="dateModified" datetime="2023-05-05T09:25:47+08:00">2023-05-05</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%89%8D%E7%AB%AF/" itemprop="url" rel="index"><span itemprop="name">前端</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>一些html5的学习笔记</p>
<span id="more"></span>

<h1 id="主要的标签和属性"><a href="#主要的标签和属性" class="headerlink" title="主要的标签和属性"></a>主要的标签和属性</h1><h2 id="新的多媒体元素"><a href="#新的多媒体元素" class="headerlink" title="新的多媒体元素"></a>新的多媒体元素</h2><table>
<thead>
<tr>
<th>标签</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><code>&lt;audio&gt;</code></td>
<td>定义音频内容</td>
</tr>
<tr>
<td><code>&lt;video&gt;</code></td>
<td>定义视频内容</td>
</tr>
<tr>
<td><code>&lt;source&gt;</code></td>
<td>定义多媒体资源，配合video或audio使用</td>
</tr>
<tr>
<td><code>&lt;embed&gt;</code></td>
<td>定义嵌入内容，个人感觉不常用</td>
</tr>
</tbody></table>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">video</span> <span class="attr">width</span>=<span class="string">&quot;321&quot;</span> <span class="attr">height</span>= <span class="string">&quot;123&quot;</span> <span class="attr">controls</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">source</span> <span class="attr">src</span>=<span class="string">&quot;movie.mp4&quot;</span> <span class="attr">type</span>=<span class="string">&quot;video/mp4&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">source</span> <span class="attr">src</span>=<span class="string">&quot;movie.ogg&quot;</span> <span class="attr">type</span>=<span class="string">&quot;video/ogg&quot;</span>&gt;</span></span><br><span class="line">您的浏览器不支持Video标签。</span><br><span class="line"><span class="tag">&lt;/<span class="name">video</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>如果浏览器不支持就会显示：您的浏览器不支持Video标签。</p>
<p>video支持是属性：<a href="#" title="如果出现该属性，则视频在就绪后马上播放。">autoplay</a> 、 <a href=# title="如果出现该属性，则向用户显示控件，比如播放按钮。">controls</a> 、<a href=# title="播放器大小">height和width</a> 、<a href=# title="如果出现该属性，则当媒介文件完成播放后再次开始播放。">loop</a> 、<a href=# title="规定视频的音频输出应该被静音。">muted</a>、<a href=# title="规定视频下载时显示的图像，或者在用户点击播放按钮前显示的图像。">poster</a>、<a href=# title="如果出现该属性，则视频在页面加载时进行加载，并预备播放。如果使用autoplay，则忽略该属性。">preload</a>、<a href=# title="要播放的视频的 URL。">src</a> 。</p>
<p>audio有：autoplay、controls、loop、muted、preload、src属性。</p>
<h2 id="新的表单元素"><a href="#新的表单元素" class="headerlink" title="新的表单元素"></a>新的表单元素</h2><table>
<thead>
<tr>
<th>标签</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><code>&lt;datalist&gt;</code></td>
<td>定义选项列表，与 input 元素配合使用，用来定义 input 可能的值。</td>
</tr>
<tr>
<td><code>&lt;keygen&gt;</code></td>
<td>规定用于表单的密钥对生成器字段。</td>
</tr>
<tr>
<td><code>&lt;output&gt;</code></td>
<td>定义不同类型的输出，比如脚本的输出。</td>
</tr>
</tbody></table>
<h2 id="新的语意标签"><a href="#新的语意标签" class="headerlink" title="新的语意标签"></a>新的语意标签</h2><table>
<thead>
<tr>
<th>标签</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td><code>&lt;article&gt;</code></td>
<td>定义内容区域</td>
</tr>
<tr>
<td><code>&lt;aside&gt;</code></td>
<td>定义侧边栏</td>
</tr>
<tr>
<td><code>&lt;command&gt;</code></td>
<td>定义命令按钮</td>
</tr>
<tr>
<td><code>&lt;details&gt;</code></td>
<td>定义细节</td>
</tr>
<tr>
<td><code>&lt;dialog&gt;</code></td>
<td>定义对话框</td>
</tr>
<tr>
<td><code>&lt;summary&gt;</code></td>
<td>标签包含 details 元素的标题</td>
</tr>
<tr>
<td><code>&lt;figure&gt;</code></td>
<td>规定独立的流内容（图像、图表、照片、代码等等）。</td>
</tr>
<tr>
<td><code>&lt;figcaption&gt;</code></td>
<td>定义<code> &lt;figure&gt;</code> 元素的标题</td>
</tr>
<tr>
<td><code>&lt;footer&gt;</code></td>
<td>定义 section 或 document 的页脚。</td>
</tr>
<tr>
<td><code>&lt;header&gt;</code></td>
<td>定义了头部区域</td>
</tr>
<tr>
<td><code>&lt;mark&gt;</code></td>
<td>定义带有记号的文本。</td>
</tr>
<tr>
<td><code>&lt;meter&gt;</code></td>
<td>定义度量衡。仅用于已知最大和最小值的度量。</td>
</tr>
<tr>
<td><code>&lt;nav&gt;</code></td>
<td>定义导航链接的部分。</td>
</tr>
<tr>
<td><code>&lt;progress&gt;</code></td>
<td>定义任何类型的任务的进度。</td>
</tr>
<tr>
<td><code>&lt;rt&gt;</code></td>
<td>定义字符（中文注音或字符）的解释或发音。</td>
</tr>
<tr>
<td><code>&lt;section&gt;</code></td>
<td>定义文档中的节（section、区段）。</td>
</tr>
<tr>
<td><code>&lt;time&gt;</code></td>
<td>定义日期或时间。</td>
</tr>
<tr>
<td><code>&lt;wbr&gt;</code></td>
<td>规定在文本中的何处适合添加换行符。</td>
</tr>
</tbody></table>
<h2 id="在HTML5中删除的HTML4-01标签"><a href="#在HTML5中删除的HTML4-01标签" class="headerlink" title="在HTML5中删除的HTML4.01标签"></a>在HTML5中删除的HTML4.01标签</h2><ul>
<li><code>&lt;acronym&gt;</code></li>
<li><code>&lt;applet&gt;</code></li>
<li><code>&lt;basefont&gt;</code></li>
<li><code>&lt;big&gt;</code></li>
<li><code>&lt;center&gt;</code></li>
<li><code>&lt;dir&gt;</code></li>
<li><code>&lt;font&gt;</code></li>
<li><code>&lt;frame&gt;</code></li>
<li><code>&lt;frameset&gt;</code></li>
<li><code>&lt;noframes&gt;</code></li>
<li><code>&lt;strike&gt;</code></li>
<li><code>&lt;tt&gt;</code></li>
</ul>
<h2 id="表单的属性"><a href="#表单的属性" class="headerlink" title="表单的属性"></a>表单的属性</h2><h3 id="form标签的属性"><a href="#form标签的属性" class="headerlink" title="form标签的属性"></a>form标签的属性</h3><table>
<thead>
<tr>
<th>属性</th>
<th>值</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>accept-charset</td>
<td>charset_list</td>
<td>规定服务器可处理的表单数据字符集。</td>
</tr>
<tr>
<td>action</td>
<td>URL</td>
<td>规定当提交表单时向何处发送表单数据。</td>
</tr>
<tr>
<td>autocomplete</td>
<td>on &#x2F; off</td>
<td>规定是否启用表单的自动完成功能。</td>
</tr>
<tr>
<td>enctype</td>
<td></td>
<td>规定在发送表单数据之前如何对其进行编码。</td>
</tr>
<tr>
<td>method</td>
<td>get&#x2F;post</td>
<td>规定用于发送 form-data 的 HTTP 方法。</td>
</tr>
<tr>
<td>name</td>
<td>form_name</td>
<td>规定表单的名称。</td>
</tr>
<tr>
<td>novalidate</td>
<td>novalidate</td>
<td>如果使用该属性，则提交表单时不进行验证。</td>
</tr>
<tr>
<td>target</td>
<td></td>
<td>规定在何处打开 action URL。</td>
</tr>
</tbody></table>
<p>enctype 属性可能的值：</p>
<ul>
<li>application&#x2F;x-www-form-urlencoded</li>
<li>multipart&#x2F;form-data</li>
<li>text&#x2F;plain</li>
</ul>
<p>target 属性可能的值：</p>
<ul>
<li>_blank</li>
<li>_self</li>
<li>_parent</li>
<li>_top</li>
<li>framename</li>
</ul>
<h1 id="Web-储存"><a href="#Web-储存" class="headerlink" title="Web 储存"></a>Web 储存</h1><h2 id="localStorage-和-sessionStorage"><a href="#localStorage-和-sessionStorage" class="headerlink" title="localStorage 和 sessionStorage"></a>localStorage 和 sessionStorage</h2><p>客户端存储数据的两个对象：</p>
<ul>
<li>localStorage - 没有时间限制</li>
<li>sessionStorage - 针对session的数据储存</li>
</ul>
<p>使用前应检查是否支持</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(<span class="title function_">typeof</span>(<span class="title class_">Storage</span>)!==<span class="string">&quot;undefined&quot;</span>) &#123;        </span><br><span class="line">    <span class="comment">// 是的! 支持 localStorage  sessionStorage 对象!         </span></span><br><span class="line">    <span class="comment">// 一些代码.....         </span></span><br><span class="line">&#125; <span class="keyword">else</span> &#123;        </span><br><span class="line">    <span class="comment">// 抱歉! 不支持 web 存储。         </span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="localStorage对象"><a href="#localStorage对象" class="headerlink" title="localStorage对象"></a>localStorage对象</h2><p>实例：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 存储</span></span><br><span class="line"><span class="variable language_">localStorage</span>.<span class="property">sitename</span> = <span class="string">&quot;Wyatex博客&quot;</span>;</span><br><span class="line"><span class="comment">// 查找</span></span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;result&quot;</span>).<span class="property">innerHTML</span> = <span class="variable language_">localStorage</span>.<span class="property">sitename</span>;</span><br></pre></td></tr></table></figure>

<p>localStorage其他可用API：</p>
<ul>
<li>保存数据：<code>localStorage.setItem(key,value);</code></li>
<li>读取数据：<code>localStorage.getItem(key);</code></li>
<li>删除单个数据：<code>localStorage.removeItem(key);</code></li>
<li>删除所有数据：<code>localStorage.clear();</code></li>
<li>得到某个索引的key：<code>localStorage.key(index);</code></li>
</ul>
<h2 id="sessionStorage对象"><a href="#sessionStorage对象" class="headerlink" title="sessionStorage对象"></a>sessionStorage对象</h2><p>用户关闭浏览器窗口后数据会删除，实例：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (<span class="variable language_">sessionStorage</span>.<span class="property">clickcount</span>) &#123;</span><br><span class="line">  <span class="variable language_">sessionStorage</span>.<span class="property">clickcount</span> = (<span class="variable language_">sessionStorage</span>.<span class="property">clickcount</span>)+<span class="number">1</span>;</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">  <span class="variable language_">sessionStorage</span>.<span class="property">clickcount</span>=<span class="number">1</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">getElementById</span>(<span class="string">&quot;counter&quot;</span>).<span class="property">innerHTML</span>=<span class="string">&quot;在这个会话中你已经点击了该按钮 &quot;</span> + <span class="variable language_">sessionStorage</span>.<span class="property">clickcount</span> + <span class="string">&quot; 次 &quot;</span>;</span><br></pre></td></tr></table></figure>

<h1 id="HTML5-应用程序缓存"><a href="#HTML5-应用程序缓存" class="headerlink" title="HTML5 应用程序缓存"></a>HTML5 应用程序缓存</h1><p>使用 HTML5，通过创建 cache manifest 文件，可以轻松地创建 web 应用的离线版本。<br>实例：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">HTML</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">manifest</span>=<span class="string">&quot;demo.appcache&quot;</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">The content of the document......</span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="manifest文件"><a href="#manifest文件" class="headerlink" title="manifest文件"></a>manifest文件</h2><p>manifest 文件是简单的文本文件，它告知浏览器被缓存的内容（以及不缓存的内容）。</p>
<p>manifest 文件可分为三个部分：</p>
<ul>
<li>CACHE MANIFEST - 在此标题下列出的文件将在首次下载后进行缓存</li>
<li>NETWORK - 在此标题下列出的文件需要与服务器的连接，且不会被缓存</li>
<li>FALLBACK - 在此标题下列出的文件规定当页面无法访问时的回退页面（比如 404 页面）</li>
</ul>
<h3 id="CACHE-MANIFEST"><a href="#CACHE-MANIFEST" class="headerlink" title="CACHE MANIFEST"></a>CACHE MANIFEST</h3><p>第一行，CACHE MANIFEST，是必需的：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">CACHE MANIFEST        </span><br><span class="line">/theme.css        </span><br><span class="line">/logo.gif        </span><br><span class="line">/main.js</span><br></pre></td></tr></table></figure>

<h3 id="NETWORK"><a href="#NETWORK" class="headerlink" title="NETWORK"></a>NETWORK</h3><p>下面的 NETWORK 小节规定文件 “login.php” 永远不会被缓存，且离线时是不可用的： </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">NETWORK:        </span><br><span class="line">login.php</span><br></pre></td></tr></table></figure>
<p>可以使用星号来指示所有其他其他资源&#x2F;文件都需要因特网连接：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">NETWORK:        </span><br><span class="line">*</span><br></pre></td></tr></table></figure>

<h3 id="FALLBACK"><a href="#FALLBACK" class="headerlink" title="FALLBACK"></a>FALLBACK</h3><p>下面的 FALLBACK 小节规定如果无法建立因特网连接，则用 “offline.html” 替代 &#x2F;html&#x2F; 目录中的所有文件：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">FALLBACK:       </span><br><span class="line">/html/ /offline.html</span><br></pre></td></tr></table></figure>
<p>第一个 URI 是资源，第二个是替补。</p>
<p>实例：完整的 Manifest 文件</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">CACHE MANIFEST        </span><br><span class="line"># 2012-02-21 v1.0.0       </span><br><span class="line">/theme.css        </span><br><span class="line">/logo.gif        </span><br><span class="line">/main.js        </span><br><span class="line">        </span><br><span class="line">NETWORK:        </span><br><span class="line">login.php        </span><br><span class="line">        </span><br><span class="line">FALLBACK:       </span><br><span class="line">/html/ /offline.html</span><br></pre></td></tr></table></figure>
<p><strong>提示</strong> : 以 “#” 开头的是注释行，但也可满足其他用途。应用的缓存会在其 manifest 文件更改时被更新。如果您编辑了一幅图片，或者修改了一个 JavaScript 函数，这些改变都不会被重新缓存。更新注释行中的日期和版本号是一种使浏览器重新缓存文件的办法。</p>
<h1 id="WebSocket"><a href="#WebSocket" class="headerlink" title="WebSocket"></a>WebSocket</h1><p>WebSocket是HTML5开始提供的一种在单个 TCP 连接上进行全双工通讯的协议。</p>
<p>在WebSocket API中，浏览器和服务器只需要做一个握手的动作，然后，浏览器和服务器之间就形成了一条快速通道。两者之间就直接可以数据互相传送。</p>
<p>浏览器通过 JavaScript 向服务器发出建立 WebSocket 连接的请求，连接建立以后，客户端和服务器端就可以通过 TCP 连接直接交换数据。</p>
<p>当你获取 Web Socket 连接后，你可以通过 send() 方法来向服务器发送数据，并通过 onmessage 事件来接收服务器返回的数据。</p>
<p>以下 API 用于创建 WebSocket 对象。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> <span class="title class_">Socket</span> = <span class="keyword">new</span> <span class="title class_">WebSocket</span>(url, [protocal] );</span><br></pre></td></tr></table></figure>
<p>以上代码中的第一个参数 url, 指定连接的 URL。第二个参数 protocol 是可选的，指定了可接受的子协议。</p>
<h2 id="WebSocket-属性"><a href="#WebSocket-属性" class="headerlink" title="WebSocket 属性"></a>WebSocket 属性</h2><p>以下是 WebSocket 对象的属性。假定我们使用了以上代码创建了 Socket 对象：</p>
<table>
    <tbody>
        <tr class="firstRow">
            <td width="401" valign="top" style="word-break: break-all;">
                属性
            </td>
            <td width="401" valign="top" style="word-break: break-all;">
                描述
            </td>
        </tr>
        <tr>
            <td width="401" valign="top" style="word-break: break-all;">
                Socket.readyState
            </td>
            <td width="401" valign="top" style="word-break: break-all;">
                <p>
                    只读属性&nbsp;readyState&nbsp;表示连接状态，可以是以下值：
                </p>
                <ul class="list list-paddingleft-2">
                    <li>
                        <p>
                            0 - 表示连接尚未建立。
                        </p>
                    </li>
                    <li>
                        <p>
                            1 - 表示连接已建立，可以进行通信。
                        </p>
                    </li>
                    <li>
                        <p>
                            2 - 表示连接正在进行关闭。
                        </p>
                    </li>
                    <li>
                        <p>
                            3 - 表示连接已经关闭或者连接不能打开。
                        </p>
                    </li>
                </ul>
            </td>
        </tr>
        <tr>
            <td width="401" valign="top" style="word-break: break-all;">
                Socket.bufferedAmount
            </td>
            <td width="401" valign="top" style="word-break: break-all;">
                只读属性&nbsp;bufferedAmount&nbsp;已被 send() 放入正在队列中等待传输，但是还没有发出的 UTF-8 文本字节数。
            </td>
        </tr>
    </tbody>
</table>

<h2 id="WebSocket-事件"><a href="#WebSocket-事件" class="headerlink" title="WebSocket 事件"></a>WebSocket 事件</h2><table class="reference" width="979" style="width: 828px;">
    <tbody style="margin: 0px; padding: 0px;">
        <tr style="margin: 0px; padding: 0px; background-color: rgb(239, 239, 239);" class="firstRow">
            <th width="10%" style="margin: 0px; padding: 3px; background-color: rgb(189, 189, 189); border-top-color: rgb(189, 189, 189); border-right-color: rgb(189, 189, 189); border-bottom: none; border-left-color: rgb(189, 189, 189); color: rgb(255, 255, 255); vertical-align: top; text-align: left;">
                事件
            </th>
            <th width="25%" style="margin: 0px; padding: 3px; background-color: rgb(189, 189, 189); border-top-color: rgb(189, 189, 189); border-right-color: rgb(189, 189, 189); border-bottom: none; border-left-color: rgb(189, 189, 189); color: rgb(255, 255, 255); vertical-align: top; text-align: left;">
                事件处理程序
            </th>
            <th style="margin: 0px; padding: 3px; background-color: rgb(189, 189, 189); border-top-color: rgb(189, 189, 189); border-right-color: rgb(189, 189, 189); border-bottom: none; border-left-color: rgb(189, 189, 189); color: rgb(255, 255, 255); vertical-align: top; text-align: left;">
                描述
            </th>
        </tr>
        <tr style="margin: 0px; padding: 0px;">
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                open
            </td>
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                Socket.onopen
            </td>
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                连接建立时触发
            </td>
        </tr>
        <tr style="margin: 0px; padding: 0px; background-color: rgb(239, 239, 239);">
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                message
            </td>
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                Socket.onmessage
            </td>
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                客户端接收服务端数据时触发
            </td>
        </tr>
        <tr style="margin: 0px; padding: 0px;">
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                error
            </td>
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                Socket.onerror
            </td>
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                通信发生错误时触发
            </td>
        </tr>
        <tr style="margin: 0px; padding: 0px; background-color: rgb(239, 239, 239);">
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                close
            </td>
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                Socket.onclose
            </td>
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                连接关闭时触发
            </td>
        </tr>
    </tbody>
</table>

<h2 id="WebSocket-方法"><a href="#WebSocket-方法" class="headerlink" title="WebSocket 方法"></a>WebSocket 方法</h2><p style="white-space: normal; margin-top: 0px; padding: 0px; overflow-wrap: break-word; color: rgb(51, 51, 51); line-height: 1.7; font-family: -apple-system, BlinkMacSystemFont, &quot;Helvetica Neue&quot;, &quot;PingFang SC&quot;, &quot;Microsoft YaHei&quot;, &quot;Source Han Sans SC&quot;, &quot;Noto Sans CJK SC&quot;, &quot;WenQuanYi Micro Hei&quot;, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);">
    以下是 WebSocket 对象的相关方法。假定我们使用了以上代码创建了 Socket 对象：
</p>
<table class="reference" width="979" style="width: 828px;">
    <tbody style="margin: 0px; padding: 0px;">
        <tr style="margin: 0px; padding: 0px; background-color: rgb(239, 239, 239);" class="firstRow">
            <th style="margin: 0px; padding: 3px; background-color: rgb(189, 189, 189); border-top-color: rgb(189, 189, 189); border-right-color: rgb(189, 189, 189); border-bottom: none; border-left-color: rgb(189, 189, 189); color: rgb(255, 255, 255); vertical-align: top; text-align: left;">
                方法
            </th>
            <th style="margin: 0px; padding: 3px; background-color: rgb(189, 189, 189); border-top-color: rgb(189, 189, 189); border-right-color: rgb(189, 189, 189); border-bottom: none; border-left-color: rgb(189, 189, 189); color: rgb(255, 255, 255); vertical-align: top; text-align: left;">
                描述
            </th>
        </tr>
        <tr style="margin: 0px; padding: 0px;">
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                Socket.send()
            </td>
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                <p style="margin-bottom: 5px; overflow-wrap: break-word; line-height: 1.7;">
                    使用连接发送数据
                </p>
            </td>
        </tr>
        <tr style="margin: 0px; padding: 0px; background-color: rgb(239, 239, 239);">
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                Socket.close()
            </td>
            <td style="margin: 0px; padding: 7px 5px; min-width: 40px; vertical-align: top; box-sizing: border-box;">
                <p style="margin-bottom: 5px; overflow-wrap: break-word; line-height: 1.7;">
                    关闭连接
                </p>
            </td>
        </tr>
    </tbody>
</table>

<h2 id="WebScoket实例"><a href="#WebScoket实例" class="headerlink" title="WebScoket实例"></a>WebScoket实例</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line">&lt;!<span class="variable constant_">DOCTYPE</span> <span class="variable constant_">HTML</span>&gt;</span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">html</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">   <span class="tag">&lt;<span class="name">head</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">   <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;utf-8&quot;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">   <span class="tag">&lt;<span class="name">title</span>&gt;</span>W3Cschool教程(w3cschool.cn)<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">	</span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;<span class="name">script</span> <span class="attr">type</span>=<span class="string">&quot;text/javascript&quot;</span>&gt;</span><span class="language-javascript"></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">         <span class="keyword">function</span> <span class="title function_">WebSocketTest</span>(<span class="params"></span>)</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">         &#123;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">            <span class="keyword">if</span> (<span class="string">&quot;WebSocket&quot;</span> <span class="keyword">in</span> <span class="variable language_">window</span>)</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">            &#123;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               <span class="title function_">alert</span>(<span class="string">&quot;您的浏览器支持 WebSocket!&quot;</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               <span class="comment">// 打开一个 web socket</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               <span class="keyword">var</span> ws = <span class="keyword">new</span> <span class="title class_">WebSocket</span>(<span class="string">&quot;ws://localhost:9998/echo&quot;</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">				</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               ws.<span class="property">onopen</span> = <span class="keyword">function</span>(<span class="params"></span>)</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               &#123;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">                  <span class="comment">// Web Socket 已连接上，使用 send() 方法发送数据</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">                  ws.<span class="title function_">send</span>(<span class="string">&quot;发送数据&quot;</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">                  <span class="title function_">alert</span>(<span class="string">&quot;数据发送中...&quot;</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               &#125;;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">				</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               ws.<span class="property">onmessage</span> = <span class="keyword">function</span> (<span class="params">evt</span>) </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               &#123; </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">                  <span class="keyword">var</span> received_msg = evt.<span class="property">data</span>;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">                  <span class="title function_">alert</span>(<span class="string">&quot;数据已接收...&quot;</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               &#125;;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">				</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               ws.<span class="property">onclose</span> = <span class="keyword">function</span>(<span class="params"></span>)</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               &#123; </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">                  <span class="comment">// 关闭 websocket</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">                  <span class="title function_">alert</span>(<span class="string">&quot;连接已关闭...&quot;</span>); </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               &#125;;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">            &#125;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">            </span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">            <span class="keyword">else</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">            &#123;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               <span class="comment">// 浏览器不支持 WebSocket</span></span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">               <span class="title function_">alert</span>(<span class="string">&quot;您的浏览器不支持 WebSocket!&quot;</span>);</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">            &#125;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">         &#125;</span></span></span><br><span class="line"><span class="language-javascript"><span class="language-xml">      </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">		</span></span><br><span class="line"><span class="language-xml">   <span class="tag">&lt;/<span class="name">head</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">   <span class="tag">&lt;<span class="name">body</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">   </span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;sse&quot;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">         <span class="tag">&lt;<span class="name">a</span> <span class="attr">href</span>=<span class="string">&quot;javascript:WebSocketTest()&quot;</span>&gt;</span>运行 WebSocket<span class="tag">&lt;/<span class="name">a</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">      <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">      </span></span><br><span class="line"><span class="language-xml">   <span class="tag">&lt;/<span class="name">body</span>&gt;</span></span></span><br><span class="line"><span class="language-xml"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span></span><br><span class="line"><span class="language-xml"></span></span><br></pre></td></tr></table></figure>
    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>Wyatex
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://wyatex.online/%E5%89%8D%E7%AB%AF/Html5%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-1/" title="Html5学习笔记（1）">https://wyatex.online/前端/Html5学习笔记-1/</a>
  </li>
  <li class="post-copyright-license">
      <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/tags/%E5%89%8D%E7%AB%AF/" rel="tag"># 前端</a>
              <a href="/tags/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" rel="tag"># 学习笔记</a>
              <a href="/tags/HTML/" rel="tag"># HTML</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/C%E8%AF%AD%E8%A8%80/C-language-learn-3/" rel="prev" title="简单易懂的C语言-3">
                  <i class="fa fa-angle-left"></i> 简单易懂的C语言-3
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/git%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0-1/" rel="next" title="git学习笔记（1）">
                  git学习笔记（1） <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2019 – 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Wyatex</span>
  </div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script size="300" alpha="0.6" zIndex="-1" src="/lib/ribbon.js/dist/ribbon.min.js"></script>
  <script src="/lib/animejs/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="/lib/@next-theme/pjax/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="/lib/@fancyapps/ui/dist/fancybox/fancybox.umd.js" integrity="sha256-q8XkJ6dj5VwSvzI8+nATCHHQG+Xv/dAZBCgqmu93zOY=" crossorigin="anonymous"></script>
  <script src="/lib/lozad/dist/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="/lib/hexo-generator-searchdb/dist/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>



  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





</body>
</html>
